package com.anuprayog.flyinghelicopter;

import java.util.ArrayList;
import java.util.ConcurrentModificationException;
import java.util.Iterator;
import java.util.Random;

import com.anuprayog.flyinghelicopter.model.Barrier;
import com.anuprayog.flyinghelicopter.model.Dhoni;
import com.anuprayog.flyinghelicopter.model.DhoniScroll;
import com.anuprayog.flyinghelicopter.model.EnemyMissile;
import com.anuprayog.flyinghelicopter.model.Expl;
import com.anuprayog.flyinghelicopter.model.ExplBarrier;
import com.anuprayog.flyinghelicopter.model.Explosion;
import com.anuprayog.flyinghelicopter.model.FinalExplosion;
import com.anuprayog.flyinghelicopter.model.Helicopter;
import com.anuprayog.flyinghelicopter.model.Missile;
import com.anuprayog.flyinghelicopter.model.ShootButton;
import com.anuprayog.flyinghelicopter.model.components.Speed;
import com.anuprayog.flyinghelicopter.model.components.Hspeed;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.GradientDrawable.Orientation;
import android.media.MediaPlayer;
import android.util.Log;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

/**
 * @author amit
 * This is the main surface that handles the ontouch events and draws
 * the images to the screen.
 */
public class MainGamePanel extends SurfaceView implements
		SurfaceHolder.Callback {

	public static String HIGH_SCORE = "com.anuprayog.flyinghelicopter.SCORE";
	public static String SOUND_OFF_STRING = "com.anuprayog.flyinghelicopter.SOUND";
	private static final float SPEED_INCREASE_FACTOR = (float) 4/3;
	private static final String TAG = MainGamePanel.class.getSimpleName();
	  
	private MainThread thread;
	private Dhoni dhoni, dhoni1, dhoni2;
	private DhoniScroll dhoniScroll;
	private ShootButton shootButton;
	public int score=0;
	private int warned=0;
	GradientDrawable grad;
	
	private String scoreString;
	private ArrayList<Barrier> barrierList = new ArrayList<Barrier>();
	private ArrayList<Helicopter> helicopterList = new ArrayList<Helicopter>();
	private ArrayList<Helicopter> helicopterList1 = new ArrayList<Helicopter>();
	private ArrayList<Helicopter> helicopterList2 = new ArrayList<Helicopter>();
	private ArrayList<Helicopter> helicopterList3 = new ArrayList<Helicopter>();
	private ArrayList<Missile> missileList = new ArrayList<Missile>();
	private ArrayList<EnemyMissile> enemyMissileList = new ArrayList<EnemyMissile>();
	
	private ExplBarrier explBarrier;
	private ArrayList<ExplBarrier> explBarrierList = new ArrayList<ExplBarrier>();
	private Explosion explosion,explosion1,explosion2,explosion3,explosion4,explosion5,explosion6,explosion7,explosion8;
	private ArrayList<Explosion> explosionList = new ArrayList<Explosion>();
	private ArrayList<Explosion> explosionList1 = new ArrayList<Explosion>();
	private ArrayList<Explosion> explosionList2 = new ArrayList<Explosion>();
	private ArrayList<Explosion> explosionList3 = new ArrayList<Explosion>();
	private ArrayList<Explosion> explosionList4 = new ArrayList<Explosion>();
	private ArrayList<Explosion> explosionList5 = new ArrayList<Explosion>();
	private ArrayList<Explosion> explosionList6 = new ArrayList<Explosion>();
	private ArrayList<Explosion> explosionList7 = new ArrayList<Explosion>();
	private ArrayList<Explosion> explosionList8 = new ArrayList<Explosion>();
	private Expl expl,expl1,expl2,expl3,expl4,expl5,expl6;
	private ArrayList<Expl> explList = new ArrayList<Expl>();
	private ArrayList<Expl> explList1 = new ArrayList<Expl>();
	private ArrayList<Expl> explList2 = new ArrayList<Expl>();
	private ArrayList<Expl> explList3 = new ArrayList<Expl>();
	private ArrayList<Expl> explList4 = new ArrayList<Expl>();
	private ArrayList<Expl> explList5 = new ArrayList<Expl>();
	private ArrayList<Expl> explList6 = new ArrayList<Expl>();
	private FinalExplosion finalExplosion,finalExplosion1,finalExplosion2,finalExplosion3,finalExplosion4,finalExplosion5,finalExplosion6,finalExplosion7,finalExplosion8;
	private ArrayList<FinalExplosion> finalExplosionList = new ArrayList<FinalExplosion>();
	private ArrayList<FinalExplosion> finalExplosionList1 = new ArrayList<FinalExplosion>();
	private ArrayList<FinalExplosion> finalExplosionList2 = new ArrayList<FinalExplosion>();
	private ArrayList<FinalExplosion> finalExplosionList3 = new ArrayList<FinalExplosion>();
	private ArrayList<FinalExplosion> finalExplosionList4 = new ArrayList<FinalExplosion>();
	private ArrayList<FinalExplosion> finalExplosionList5 = new ArrayList<FinalExplosion>();
	private ArrayList<FinalExplosion> finalExplosionList6 = new ArrayList<FinalExplosion>();
	private ArrayList<FinalExplosion> finalExplosionList7 = new ArrayList<FinalExplosion>();
	private ArrayList<FinalExplosion> finalExplosionList8 = new ArrayList<FinalExplosion>();
	
	private int cycle=0;
	private int xcycle;
	private int drawcycle=0;
	private int speedIncreaser=0;
	private int speedVector;
	public boolean paused;
	private boolean restart;
	private int explosioncycle;
	private int explcycle;
	private int finalExplosioncycle;
	
	private boolean newGame;
	private boolean upped;
	
	private Bitmap scroll = BitmapFactory.decodeResource(getResources(), R.drawable.scroll);
	/*private Bitmap background = BitmapFactory.decodeResource(getResources(), R.drawable.cloud2);
	
	private Bitmap scorer = BitmapFactory.decodeResource(getResources(), R.drawable.scorer);
	private Bitmap pause = BitmapFactory.decodeResource(getResources(), R.drawable.pause);
	private Bitmap resume = BitmapFactory.decodeResource(getResources(), R.drawable.resume);
	
	private Bitmap zero = BitmapFactory.decodeResource(getResources(), R.drawable.zero);
	private Bitmap one = BitmapFactory.decodeResource(getResources(), R.drawable.one);
	private Bitmap two = BitmapFactory.decodeResource(getResources(), R.drawable.two);
	private Bitmap three = BitmapFactory.decodeResource(getResources(), R.drawable.three);
	private Bitmap four = BitmapFactory.decodeResource(getResources(), R.drawable.four);
	private Bitmap five = BitmapFactory.decodeResource(getResources(), R.drawable.five);
	private Bitmap six = BitmapFactory.decodeResource(getResources(), R.drawable.six);
	private Bitmap seven = BitmapFactory.decodeResource(getResources(), R.drawable.seven);
	private Bitmap eight = BitmapFactory.decodeResource(getResources(), R.drawable.eight);
	private Bitmap nine = BitmapFactory.decodeResource(getResources(), R.drawable.nine);*/
	
	private MediaPlayer blast = MediaPlayer.create((Activity)getContext(), R.raw.blast);
	private MediaPlayer barrierBlast = MediaPlayer.create((Activity)getContext(), R.raw.barrierblast);
	private MediaPlayer missileBlast = MediaPlayer.create((Activity)getContext(), R.raw.missileblast);

	Intent in = ((Activity)getContext()).getIntent();
	Paint paint = new Paint();
	
	private String soundoff = in.getStringExtra(MainActivity.SOUND_ON_STRING);
		
	public MainGamePanel(Context context) {
		super(context);
		// adding the callback (this) to the surface holder to intercept events
		getHolder().addCallback(this);

		// create the game loop thread
		thread = new MainThread(getHolder(), this);
		
		// make the GamePanel focusable so it can handle events
		setFocusable(true);
		
		// set gradient background
        grad = new GradientDrawable(Orientation.LEFT_RIGHT,
                new int[]{0xff80aa80, 0xff00aa80});
              //grad.setBounds(0, 0, 640, 480);
	}

	@Override
	public void surfaceChanged(SurfaceHolder holder, int format, int width,
			int height) {
	}

	@Override
	public void surfaceCreated(SurfaceHolder holder) {

		int wd = this.getWidth();
		int ht = this.getHeight();
		
		// create droid and load bitmap
		dhoni = new Dhoni(BitmapFactory.decodeResource(getResources(), R.drawable.dhoni0), wd/6, ht/2);
		dhoni1 = new Dhoni(BitmapFactory.decodeResource(getResources(), R.drawable.dhoni1), wd/6, ht/2);
		dhoni2 = new Dhoni(BitmapFactory.decodeResource(getResources(), R.drawable.dhoni2), wd/6, ht/2);
		dhoniScroll = new DhoniScroll(BitmapFactory.decodeResource(getResources(), R.drawable.dhoniscroll), wd/30, ht/2);
		shootButton = new ShootButton(BitmapFactory.decodeResource(getResources(), R.drawable.shoot), 17*(wd/18), 11*(ht/12));
		
		//if it is the first time the thread starts
		if(thread.getState() == Thread.State.NEW){
		thread.setRunning(true);
		thread.start();
		newGame = true;
		}
	
		//after a pause it starts the thread again
		else
		if (thread.getState() == Thread.State.TERMINATED){
		Log.d(TAG,"coming back from pause");
		thread = new MainThread(getHolder(), this);
		thread.setRunning(true);
		thread.start(); // Start a new thread
		restart = true;
		}

		if (restart) {
			thread.setRunning(false);
			paused = true;
		}
		
		if (newGame) {
			thread.setRunning(false);
			paused = true;
		} 
	}

	@Override
	public void surfaceDestroyed(SurfaceHolder holder) {
		// tell the thread to shut down and wait for it to finish
		// this is a clean shutdown
		boolean retry = true;
		while (retry) {
			try {
				thread.join();
				retry = false;
			} catch (InterruptedException e) {
				// try again shutting down the thread
			}
		}
	}
	
	/*@Override
	public boolean onTouchEvent(MotionEvent event) {
		if (event.getAction() == MotionEvent.ACTION_DOWN) {
			// delegating event handling to the smilies giving score of 1 on punching sad smilies and a warning on punching happy smilies
			
			//pause-resume function
			if (event.getX() < getWidth()/5) {
				if (event.getY() < 2*getHeight()/15) {
					if (!paused){
		                thread.setRunning(false);
		                paused=true;
		            } else if (paused){
		            	thread = new MainThread(getHolder(), this);
		        		thread.setRunning(true);
		        		thread.start();
						paused=false;
					}
				}
			}
			// delegating event handling to the helicopter
			dhoniScroll.handleActionDown((int)event.getX(), (int)event.getY());
			upped=false;
			            
            if(newGame){
				if(dhoniScroll.isTouched()){
					thread = new MainThread(getHolder(), this);
					thread.setRunning(true);
	        		thread.start();
					paused=false;
					newGame=false;
				}
			}
            
            shootButton.handleActionDown((int)event.getX(), (int)event.getY());
			if(shootButton.isTouched()){
        		Missile missile = new Missile(BitmapFactory.decodeResource(getResources(), R.drawable.missile), dhoni.getX() + getWidth()/16, dhoni.getY());
    			missile.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
    			missileList.add(missile);
        	}
            
        } if (event.getAction() == MotionEvent.ACTION_MOVE) {
			// the gestures
        	if(dhoniScroll.isTouched()){
	            if (!paused) {
	                // the helicopter was picked up and is being dragged
	            	//dhoni.setX((int)event.getX());
	            	dhoniScroll.setY((int)event.getY());
	            	dhoni.setY((int)event.getY());
	            	dhoni1.setY((int)event.getY());
	            	dhoni2.setY((int)event.getY());
	            	
	            }
        	}
        } if (event.getAction() == MotionEvent.ACTION_UP) {
			// touch was released
            if (dhoniScroll.isTouched()) {
            	dhoniScroll.setTouched(false);
            	upped=true;
            }
            
            if (shootButton.isTouched()) {
    			shootButton.setTouched(false);
            }
            
                //upped=true;
	            
            if (event.getX() < getWidth()/5) {
				if (event.getY() < 2*getHeight()/15) {
					if (!paused){
		                paused=false;
		            } else if (paused){
		            	paused=true;
					}
				}
			}
			
		}
    	return true;
	}*/
	
	@Override
	  public boolean onTouchEvent(MotionEvent event) {

	    // get pointer index from the event object
	    int pointerIndex = event.getActionIndex();

	    // get pointer ID
	    int pointerId = event.getPointerId(pointerIndex);

	    // get masked (not specific to a pointer) action
	    int maskedAction = event.getActionMasked();

	    switch (maskedAction) {

	    case MotionEvent.ACTION_DOWN:
	    case MotionEvent.ACTION_POINTER_DOWN: {
	      // We have a new pointer. Lets add it to the list of pointers

	      PointF f = new PointF();
	      f.x = event.getX(pointerIndex);
	      f.y = event.getY(pointerIndex);
	      //mActivePointers.put(pointerId, f);
	    	// delegating event handling to the helicopter
			dhoniScroll.handleActionDown((int)event.getX(pointerIndex), (int)event.getY(pointerIndex));
			upped=false;
			            
            if(newGame){
				if(dhoniScroll.isTouched()){
					thread = new MainThread(getHolder(), this);
					thread.setRunning(true);
	        		thread.start();
					paused=false;
					newGame=false;
				}
			}
            
            /*if(restart){
				if(dhoniScroll.isTouched()){
					thread = new MainThread(getHolder(), this);
					thread.setRunning(true);
	        		thread.start();
					paused=false;
					restart=false;
				}
			}*/
            
            shootButton.handleActionDown((int)event.getX(pointerIndex), (int)event.getY(pointerIndex));
			if(shootButton.isTouched()){
        		Missile missile = new Missile(BitmapFactory.decodeResource(getResources(), R.drawable.missile), dhoni.getX() + getWidth()/16, dhoni.getY());
    			missile.getSpeed().setXv((float) (getWidth()/160 * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
    			missileList.add(missile);
        	}
			
			/*if (event.getX() > getWidth()/10 && event.getX() < getWidth()/5) {
				if (event.getY() < 2*getHeight()/15) {
					if (!paused){
		                thread.setRunning(false);
		                paused=true;
		            } else if (paused){
		            	thread = new MainThread(getHolder(), this);
		        		thread.setRunning(true);
		        		thread.start();
						paused=false;
					}
				}
			}*/
	    	
	      break;
	    }
	    case MotionEvent.ACTION_MOVE: { // a pointer was moved
	      /*for (int size = event.getPointerCount(), i = 0; i < size; i++) {
	        PointF point = mActivePointers.get(event.getPointerId(i));
	        if (point != null) {
	          point.x = event.getX(i);
	          point.y = event.getY(i);
	        }
	      }*/
	    	// the gestures
	    	dhoniScroll.handleActionDown((int)event.getX(pointerIndex), (int)event.getY(pointerIndex));
			
        	if(dhoniScroll.isTouched()){
	            if (!paused) {
	                // the helicopter was picked up and is being dragged
	            	//dhoni.setX((int)event.getX());
	            	dhoniScroll.setY((int)event.getY(pointerIndex));
	            	dhoni.setY((int)event.getY(pointerIndex));
	            	dhoni1.setY((int)event.getY(pointerIndex));
	            	dhoni2.setY((int)event.getY(pointerIndex));
	            	
	            }
        	}
	      break;
	    }
	    case MotionEvent.ACTION_UP: {
	    	// touch was released
            if (dhoniScroll.isTouched()) {
            	dhoniScroll.setTouched(false);
            	upped=true;
            }
            
            if (!(dhoniScroll.isTouched())) {
            	upped=true;
            }
	    }
	    case MotionEvent.ACTION_POINTER_UP: {
	    	if (shootButton.isTouched()) {
    			shootButton.setTouched(false);
            }
	    	
	    	/*if (event.getX() > getWidth()/10 && event.getX() < getWidth()/5) {
				if (event.getY() < 2*getHeight()/15) {
					if (!paused){
		                paused=false;
		            } else if (paused){
		            	paused=true;
					}
				}
			}*/
	    	
	    	/*if (dhoniScroll.isTouched()) {
            	dhoniScroll.setTouched(true);
            
            	//dhoniScroll.handleActionDown((int)event.getX(pointerIndex), (int)event.getY(pointerIndex));
    			upped=false;
	    	
	    	}	*/    	    	
	    }
	    case MotionEvent.ACTION_CANCEL: {
	      //mActivePointers.remove(pointerId);
	      break;
	    }
	    }
	    invalidate();

	    return true;
	  }

	@SuppressLint("DrawAllocation")
	@Override
	protected void onDraw(Canvas canvas) {
		grad.setBounds(0, 0, getWidth(), getHeight());
        grad.draw(canvas);
        
		drawcycle= drawcycle + 1;
		
		// fills the canvas with smilies
		if(warned==0){
			if(cycle%3==0){
				dhoni.draw(canvas);
			}else if(cycle%3==1){
				dhoni1.draw(canvas);
			}else {
				dhoni2.draw(canvas);
			}
		}else{
		}
		try {
			for(int i=0;i<barrierList.size();i++)
			{
				barrierList.get(i).draw(canvas);
			}
			for(int i=0;i<helicopterList.size();i++)
			{
				if(cycle%4==0){
					helicopterList.get(i).draw(canvas);
				}else if(cycle%4==1){
					helicopterList1.get(i).draw(canvas);
				}else if(cycle%4==2){
					helicopterList2.get(i).draw(canvas);
				}else {
					helicopterList3.get(i).draw(canvas);
				}
				
			}
			for(int i=0;i<missileList.size();i++)
			{
				missileList.get(i).draw(canvas);
			}
			for(int i=0;i<enemyMissileList.size();i++)
			{
				enemyMissileList.get(i).draw(canvas);
			}
			Iterator<ExplBarrier> iter = explBarrierList.iterator();
			while (iter.hasNext()) {
				iter.next().draw(canvas);
			}
			
			for(int i=0;i<explosionList.size();i++)
			{
				if(cycle < explosioncycle+3){
					explosionList.get(i).draw(canvas);
				}else if((cycle >= explosioncycle+3) && (cycle < explosioncycle+6)){
					explosionList1.get(i).draw(canvas);
				}else if((cycle >= explosioncycle+6) && (cycle < explosioncycle+9)){
					explosionList2.get(i).draw(canvas);
				}else if((cycle >= explosioncycle+9) && (cycle < explosioncycle+12)){
					explosionList3.get(i).draw(canvas);
				}else if((cycle >= explosioncycle+12) && (cycle < explosioncycle+15)){
					explosionList4.get(i).draw(canvas);
				}else if((cycle >= explosioncycle+15) && (cycle < explosioncycle+18)){
					explosionList5.get(i).draw(canvas);
				}else if((cycle >= explosioncycle+18) && (cycle < explosioncycle+21)){
					explosionList6.get(i).draw(canvas);
				}else if((cycle >= explosioncycle+21) && (cycle < explosioncycle+24)){
					explosionList7.get(i).draw(canvas);
				}else if((cycle >= explosioncycle+24) && (cycle < explosioncycle+27)){
					explosionList8.get(i).draw(canvas);
				}
			}
			
			for(int i=0;i<explList.size();i++)
			{
				if(cycle < explcycle+3){
					explList.get(i).draw(canvas);
				}else if((cycle >= explcycle+3) && (cycle < explcycle+6)){
					explList1.get(i).draw(canvas);
				}else if((cycle >= explcycle+6) && (cycle < explcycle+9)){
					explList2.get(i).draw(canvas);
				}else if((cycle >= explcycle+9) && (cycle < explcycle+12)){
					explList3.get(i).draw(canvas);
				}else if((cycle >= explcycle+12) && (cycle < explcycle+15)){
					explList4.get(i).draw(canvas);
				}else if((cycle >= explcycle+15) && (cycle < explcycle+18)){
					explList5.get(i).draw(canvas);
				}else if((cycle >= explcycle+18) && (cycle < explcycle+21)){
					explList6.get(i).draw(canvas);
				}
			}
			
			for(int i=0;i<finalExplosionList.size();i++)
			{
				if(cycle < finalExplosioncycle+3){
					finalExplosionList.get(i).draw(canvas);
				}else if((cycle >= finalExplosioncycle+3) && (cycle < finalExplosioncycle+6)){
					finalExplosionList1.get(i).draw(canvas);
				}else if((cycle >= finalExplosioncycle+6) && (cycle < finalExplosioncycle+9)){
					finalExplosionList2.get(i).draw(canvas);
				}else if((cycle >= finalExplosioncycle+9) && (cycle < finalExplosioncycle+12)){
					finalExplosionList3.get(i).draw(canvas);
				}else if((cycle >= finalExplosioncycle+12) && (cycle < finalExplosioncycle+15)){
					finalExplosionList4.get(i).draw(canvas);
				}else if((cycle >= finalExplosioncycle+15) && (cycle < finalExplosioncycle+18)){
					finalExplosionList5.get(i).draw(canvas);
				}else if((cycle >= finalExplosioncycle+18) && (cycle < finalExplosioncycle+21)){
					finalExplosionList6.get(i).draw(canvas);
				}else if((cycle >= finalExplosioncycle+21) && (cycle < finalExplosioncycle+24)){
					finalExplosionList7.get(i).draw(canvas);
				}else if((cycle >= finalExplosioncycle+24) && (cycle < finalExplosioncycle+27)){
					finalExplosionList8.get(i).draw(canvas);
				}
			}
		} catch (IndexOutOfBoundsException e) {
			
		} catch (NullPointerException e) {
			
		}	
		
		
	    paint.setARGB(255, 255, 255, 255);
	    
	    paint.setTextSize(this.getHeight()/20);
	    
	    //draw the pause and resume buttons
	    /*if(!(MainThread.running)){
	    	canvas.drawBitmap(resume, null, new Rect(getWidth()/10,0,getWidth()/5, 2*(getHeight()/15)), paint);
		} else if(MainThread.running){
			canvas.drawBitmap(pause, null, new Rect(getWidth()/10,0,getWidth()/5, 2*(getHeight()/15)), paint);
		}*/
	    
	    scoreString = String.valueOf(score);
	    
	    paint.setColor(Color.RED);
        paint.setStyle(Paint.Style.FILL);
        //turn antialiasing on
        paint.setAntiAlias(true);
        
        // show score and warnings
		canvas.drawText("SCORE:" + scoreString, 3*getWidth()/4, getHeight()/20, paint);
		
		if(newGame){
		
			/*thread.setRunning(false);
			paused = true;*/
			canvas.drawText("READY", getWidth()/2, getHeight()/3, paint);
			canvas.drawText("CLICK BUTTON TO START", getWidth()/2, 2*(getHeight()/3), paint);
			
		}
		
		/*canvas.drawBitmap(scorer, null, new Rect(this.getWidth()/2, this.getHeight()/30, 7*this.getWidth()/10, this.getHeight()/15), paint);
		
		scoreString = String.valueOf(score);
		
		//parsing score string to print score in the canvas
		if (scoreString.charAt(0) == '0'){
			canvas.drawBitmap(zero, null, new Rect(7*this.getWidth()/10, this.getHeight()/30, 3*this.getWidth()/4, this.getHeight()/15), paint);
		} else if (scoreString.charAt(0) == '1'){
			canvas.drawBitmap(one, null, new Rect(7*this.getWidth()/10, this.getHeight()/30, 3*this.getWidth()/4, this.getHeight()/15), paint);
		} else if (scoreString.charAt(0) == '2'){
			canvas.drawBitmap(two, null, new Rect(7*this.getWidth()/10, this.getHeight()/30, 3*this.getWidth()/4, this.getHeight()/15), paint);
		} else if (scoreString.charAt(0) == '3'){
			canvas.drawBitmap(three, null, new Rect(7*this.getWidth()/10, this.getHeight()/30, 3*this.getWidth()/4, this.getHeight()/15), paint);
		} else if (scoreString.charAt(0) == '4'){
			canvas.drawBitmap(four, null, new Rect(7*this.getWidth()/10, this.getHeight()/30, 3*this.getWidth()/4, this.getHeight()/15), paint);
		} else if (scoreString.charAt(0) == '5'){
			canvas.drawBitmap(five, null, new Rect(7*this.getWidth()/10, this.getHeight()/30, 3*this.getWidth()/4, this.getHeight()/15), paint);
		} else if (scoreString.charAt(0) == '6'){
			canvas.drawBitmap(six, null, new Rect(7*this.getWidth()/10, this.getHeight()/30, 3*this.getWidth()/4, this.getHeight()/15), paint);
		} else if (scoreString.charAt(0) == '7'){
			canvas.drawBitmap(seven, null, new Rect(7*this.getWidth()/10, this.getHeight()/30, 3*this.getWidth()/4, this.getHeight()/15), paint);
		} else if (scoreString.charAt(0) == '8'){
			canvas.drawBitmap(eight, null, new Rect(7*this.getWidth()/10, this.getHeight()/30, 3*this.getWidth()/4, this.getHeight()/15), paint);
		} else if (scoreString.charAt(0) == '9'){
			canvas.drawBitmap(nine, null, new Rect(7*this.getWidth()/10, this.getHeight()/30, 3*this.getWidth()/4, this.getHeight()/15), paint);
		} 
		
		if (score>9){
			if (scoreString.charAt(1) == '0'){
				canvas.drawBitmap(zero, null, new Rect(3*this.getWidth()/4, this.getHeight()/30, 4*this.getWidth()/5, this.getHeight()/15), paint);
			} else if (scoreString.charAt(1) == '1'){
				canvas.drawBitmap(one, null, new Rect(3*this.getWidth()/4, this.getHeight()/30, 4*this.getWidth()/5, this.getHeight()/15), paint);
			} else if (scoreString.charAt(1) == '2'){
				canvas.drawBitmap(two, null, new Rect(3*this.getWidth()/4, this.getHeight()/30, 4*this.getWidth()/5, this.getHeight()/15), paint);
			} else if (scoreString.charAt(1) == '3'){
				canvas.drawBitmap(three, null, new Rect(3*this.getWidth()/4, this.getHeight()/30, 4*this.getWidth()/5, this.getHeight()/15), paint);
			} else if (scoreString.charAt(1) == '4'){
				canvas.drawBitmap(four, null, new Rect(3*this.getWidth()/4, this.getHeight()/30, 4*this.getWidth()/5, this.getHeight()/15), paint);
			} else if (scoreString.charAt(1) == '5'){
				canvas.drawBitmap(five, null, new Rect(3*this.getWidth()/4, this.getHeight()/30, 4*this.getWidth()/5, this.getHeight()/15), paint);
			} else if (scoreString.charAt(1) == '6'){
				canvas.drawBitmap(six, null, new Rect(3*this.getWidth()/4, this.getHeight()/30, 4*this.getWidth()/5, this.getHeight()/15), paint);
			} else if (scoreString.charAt(1) == '7'){
				canvas.drawBitmap(seven, null, new Rect(3*this.getWidth()/4, this.getHeight()/30, 4*this.getWidth()/5, this.getHeight()/15), paint);
			} else if (scoreString.charAt(1) == '8'){
				canvas.drawBitmap(eight, null, new Rect(3*this.getWidth()/4, this.getHeight()/30, 4*this.getWidth()/5, this.getHeight()/15), paint);
			} else if (scoreString.charAt(1) == '9'){
				canvas.drawBitmap(nine, null, new Rect(3*this.getWidth()/4, this.getHeight()/30, 4*this.getWidth()/5, this.getHeight()/15), paint);
			} 
		}
		
		if (score>99){
			if (scoreString.charAt(2) == '0'){
				canvas.drawBitmap(zero, null, new Rect(4*this.getWidth()/5, this.getHeight()/30, 17*this.getWidth()/20, this.getHeight()/15), paint);
			} else if (scoreString.charAt(2) == '1'){
				canvas.drawBitmap(one, null, new Rect(4*this.getWidth()/5, this.getHeight()/30, 17*this.getWidth()/20, this.getHeight()/15), paint);
			} else if (scoreString.charAt(2) == '2'){
				canvas.drawBitmap(two, null, new Rect(4*this.getWidth()/5, this.getHeight()/30, 17*this.getWidth()/20, this.getHeight()/15), paint);
			} else if (scoreString.charAt(2) == '3'){
				canvas.drawBitmap(three, null, new Rect(4*this.getWidth()/5, this.getHeight()/30, 17*this.getWidth()/20, this.getHeight()/15), paint);
			} else if (scoreString.charAt(2) == '4'){
				canvas.drawBitmap(four, null, new Rect(4*this.getWidth()/5, this.getHeight()/30, 17*this.getWidth()/20, this.getHeight()/15), paint);
			} else if (scoreString.charAt(2) == '5'){
				canvas.drawBitmap(five, null, new Rect(4*this.getWidth()/5, this.getHeight()/30, 17*this.getWidth()/20, this.getHeight()/15), paint);
			} else if (scoreString.charAt(2) == '6'){
				canvas.drawBitmap(six, null, new Rect(4*this.getWidth()/5, this.getHeight()/30, 17*this.getWidth()/20, this.getHeight()/15), paint);
			} else if (scoreString.charAt(2) == '7'){
				canvas.drawBitmap(seven, null, new Rect(4*this.getWidth()/5, this.getHeight()/30, 17*this.getWidth()/20, this.getHeight()/15), paint);
			} else if (scoreString.charAt(2) == '8'){
				canvas.drawBitmap(eight, null, new Rect(4*this.getWidth()/5, this.getHeight()/30, 17*this.getWidth()/20, this.getHeight()/15), paint);
			} else if (scoreString.charAt(2) == '9'){
				canvas.drawBitmap(nine, null, new Rect(4*this.getWidth()/5, this.getHeight()/30, 17*this.getWidth()/20, this.getHeight()/15), paint);
			} 
		}
		
		if (score>999){
			if (scoreString.charAt(3) == '0'){
				canvas.drawBitmap(zero, null, new Rect(17*this.getWidth()/20, this.getHeight()/30, 9*this.getWidth()/10, this.getHeight()/15), paint);
			} else if (scoreString.charAt(3) == '1'){
				canvas.drawBitmap(one, null, new Rect(17*this.getWidth()/20, this.getHeight()/30, 9*this.getWidth()/10, this.getHeight()/15), paint);
			} else if (scoreString.charAt(3) == '2'){
				canvas.drawBitmap(two, null, new Rect(17*this.getWidth()/20, this.getHeight()/30, 9*this.getWidth()/10, this.getHeight()/15), paint);
			} else if (scoreString.charAt(3) == '3'){
				canvas.drawBitmap(three, null, new Rect(17*this.getWidth()/20, this.getHeight()/30, 9*this.getWidth()/10, this.getHeight()/15), paint);
			} else if (scoreString.charAt(3) == '4'){
				canvas.drawBitmap(four, null, new Rect(17*this.getWidth()/20, this.getHeight()/30, 9*this.getWidth()/10, this.getHeight()/15), paint);
			} else if (scoreString.charAt(3) == '5'){
				canvas.drawBitmap(five, null, new Rect(17*this.getWidth()/20, this.getHeight()/30, 9*this.getWidth()/10, this.getHeight()/15), paint);
			} else if (scoreString.charAt(3) == '6'){
				canvas.drawBitmap(six, null, new Rect(17*this.getWidth()/20, this.getHeight()/30, 9*this.getWidth()/10, this.getHeight()/15), paint);
			} else if (scoreString.charAt(3) == '7'){
				canvas.drawBitmap(seven, null, new Rect(17*this.getWidth()/20, this.getHeight()/30, 9*this.getWidth()/10, this.getHeight()/15), paint);
			} else if (scoreString.charAt(3) == '8'){
				canvas.drawBitmap(eight, null, new Rect(17*this.getWidth()/20, this.getHeight()/30, 9*this.getWidth()/10, this.getHeight()/15), paint);
			} else if (scoreString.charAt(3) == '9'){
				canvas.drawBitmap(nine, null, new Rect(17*this.getWidth()/20, this.getHeight()/30, 9*this.getWidth()/10, this.getHeight()/15), paint);
			} 
		}
		
		if (score>9999){
			if (scoreString.charAt(4) == '0'){
				canvas.drawBitmap(zero, null, new Rect(9*this.getWidth()/10, this.getHeight()/30, 19*this.getWidth()/20, this.getHeight()/15), paint);
			} else if (scoreString.charAt(4) == '1'){
				canvas.drawBitmap(one, null, new Rect(9*this.getWidth()/10, this.getHeight()/30, 19*this.getWidth()/20, this.getHeight()/15), paint);
			} else if (scoreString.charAt(4) == '2'){
				canvas.drawBitmap(two, null, new Rect(9*this.getWidth()/10, this.getHeight()/30, 19*this.getWidth()/20, this.getHeight()/15), paint);
			} else if (scoreString.charAt(4) == '3'){
				canvas.drawBitmap(three, null, new Rect(9*this.getWidth()/10, this.getHeight()/30, 19*this.getWidth()/20, this.getHeight()/15), paint);
			} else if (scoreString.charAt(4) == '4'){
				canvas.drawBitmap(four, null, new Rect(9*this.getWidth()/10, this.getHeight()/30, 19*this.getWidth()/20, this.getHeight()/15), paint);
			} else if (scoreString.charAt(4) == '5'){
				canvas.drawBitmap(five, null, new Rect(9*this.getWidth()/10, this.getHeight()/30, 19*this.getWidth()/20, this.getHeight()/15), paint);
			} else if (scoreString.charAt(4) == '6'){
				canvas.drawBitmap(six, null, new Rect(9*this.getWidth()/10, this.getHeight()/30, 19*this.getWidth()/20, this.getHeight()/15), paint);
			} else if (scoreString.charAt(4) == '7'){
				canvas.drawBitmap(seven, null, new Rect(9*this.getWidth()/10, this.getHeight()/30, 19*this.getWidth()/20, this.getHeight()/15), paint);
			} else if (scoreString.charAt(4) == '8'){
				canvas.drawBitmap(eight, null, new Rect(9*this.getWidth()/10, this.getHeight()/30, 19*this.getWidth()/20, this.getHeight()/15), paint);
			} else if (scoreString.charAt(4) == '9'){
				canvas.drawBitmap(nine, null, new Rect(9*this.getWidth()/10, this.getHeight()/30, 19*this.getWidth()/20, this.getHeight()/15), paint);
			} 
		}
		
		if (score>99999){
			if (scoreString.charAt(5) == '0'){
				canvas.drawBitmap(zero, null, new Rect(19*this.getWidth()/20, this.getHeight()/30, this.getWidth(), this.getHeight()/15), paint);
			} else if (scoreString.charAt(5) == '1'){
				canvas.drawBitmap(one, null, new Rect(19*this.getWidth()/20, this.getHeight()/30, this.getWidth(), this.getHeight()/15), paint);
			} else if (scoreString.charAt(5) == '2'){
				canvas.drawBitmap(two, null, new Rect(19*this.getWidth()/20, this.getHeight()/30, this.getWidth(), this.getHeight()/15), paint);
			} else if (scoreString.charAt(5) == '3'){
				canvas.drawBitmap(three, null, new Rect(19*this.getWidth()/20, this.getHeight()/30, this.getWidth(), this.getHeight()/15), paint);
			} else if (scoreString.charAt(5) == '4'){
				canvas.drawBitmap(four, null, new Rect(19*this.getWidth()/20, this.getHeight()/30, this.getWidth(), this.getHeight()/15), paint);
			} else if (scoreString.charAt(5) == '5'){
				canvas.drawBitmap(five, null, new Rect(19*this.getWidth()/20, this.getHeight()/30, this.getWidth(), this.getHeight()/15), paint);
			} else if (scoreString.charAt(5) == '6'){
				canvas.drawBitmap(six, null, new Rect(19*this.getWidth()/20, this.getHeight()/30, this.getWidth(), this.getHeight()/15), paint);
			} else if (scoreString.charAt(5) == '7'){
				canvas.drawBitmap(seven, null, new Rect(19*this.getWidth()/20, this.getHeight()/30, this.getWidth(), this.getHeight()/15), paint);
			} else if (scoreString.charAt(5) == '8'){
				canvas.drawBitmap(eight, null, new Rect(19*this.getWidth()/20, this.getHeight()/30, this.getWidth(), this.getHeight()/15), paint);
			} else if (scoreString.charAt(5) == '9'){
				canvas.drawBitmap(nine, null, new Rect(19*this.getWidth()/20, this.getHeight()/30, this.getWidth(), this.getHeight()/15), paint);
			} 
		}*/
		
		canvas.drawBitmap(scroll, null, new Rect(0,0,getWidth()/15, getHeight()), paint);
		dhoniScroll.draw(canvas);
		shootButton.draw(canvas);
		
	}
	
	/**
	 * This is the game update method. It iterates through all the objects
	 * and calls their update method if they have one or calls specific
	 * engine's update method.
	 */
	public void update() {
		
		Random ran = new Random();
		Random ranx = new Random();
		Random ran2 = new Random();
		Random ranh = new Random();
		Random ranhh = new Random();
		int x,xx,x2,xh,xhh,x1=0;
		
		int z = getWidth();
				
		int aa = getHeight();
		
		cycle = cycle+1; //count update cycles
		xcycle = xcycle+1;
		
		if(cycle%5==0){
			score++;
		}
		
		//Increase speed after 2000 update cycles are completed
		//if(xcycle == 1200){
			
			
			/*if(speedIncreaser<5){
				speedIncreaser = speedIncreaser+1;
			}else{
				speedIncreaser = 5;
			}*/
			
			
			/*try {
				for(int i=0;i<coinList.size();i++)
				{
					coinList.get(i).getSpeed().increaseSpeed();
					coinList1.get(i).getSpeed().increaseSpeed();
				}
				for(int i=0;i<bombList.size();i++)
				{
					bombList.get(i).getSpeed().increaseSpeed();
					bombList1.get(i).getSpeed().increaseSpeed();
				}
				for(int i=0;i<diamondList.size();i++)
				{
					diamondList.get(i).getSpeed().increaseSpeed();
				}
				for(int i=0;i<ffwdList.size();i++)
				{
					ffwdList.get(i).getSpeed().increaseSpeed();
				}
				for(int i=0;i<slowList.size();i++)
				{
					slowList.get(i).getSpeed().increaseSpeed();
				}
				for(int i=0;i<tenList.size();i++)
				{
					tenList.get(i).getScoreSpeed().increaseSpeed();
				}
				for(int i=0;i<hundredList.size();i++)
				{
					hundredList.get(i).getScoreSpeed().increaseSpeed();
				}
			} catch (IndexOutOfBoundsException e) {
				
			} catch (NullPointerException e) {
				
			}*/
			//xcycle=0;
			
		//}
		
		speedVector = z/160;
		
		/*if(speedVector>=4){
			speedVector = 4;
		}*/
		
		if(cycle==2)
		{
			int d,dd;
			Random ranc = new Random();
			Random rand = new Random();
			
			for(int i=0;i<12;i++)
			{
				d = ranc.nextInt(4);
				
				if(d==0){
					Barrier barrier = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), i*(getWidth()/10), getHeight()/40);
					barrier.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
					barrier.getSpeed().toggleXDirection();
					barrierList.add(barrier);
				} else if(d==1){
					Barrier barrier = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), i*(getWidth()/10), getHeight()/40);
					barrier.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
					barrier.getSpeed().toggleXDirection();
					barrierList.add(barrier);
					Barrier barrier1 = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), i*(getWidth()/10), 3*(getHeight()/40));
					barrier1.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
					barrier1.getSpeed().toggleXDirection();
					barrierList.add(barrier1);
				} else if(d==2){
					Barrier barrier = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), i*(getWidth()/10), getHeight()/40);
					barrier.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
					barrier.getSpeed().toggleXDirection();
					barrierList.add(barrier);
					Barrier barrier1 = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), i*(getWidth()/10), 3*(getHeight()/40));
					barrier1.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
					barrier1.getSpeed().toggleXDirection();
					barrierList.add(barrier1);
					Barrier barrier2 = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), i*(getWidth()/10), getHeight()/8);
					barrier2.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
					barrier2.getSpeed().toggleXDirection();
					barrierList.add(barrier2);
				} else if(d==3){
					Barrier barrier = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), i*(getWidth()/10), getHeight()/40);
					barrier.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
					barrier.getSpeed().toggleXDirection();
					barrierList.add(barrier);
					Barrier barrier1 = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), i*(getWidth()/10), 3*(getHeight()/40));
					barrier1.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
					barrier1.getSpeed().toggleXDirection();
					barrierList.add(barrier1);
					Barrier barrier2 = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), i*(getWidth()/10), getHeight()/8);
					barrier2.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
					barrier2.getSpeed().toggleXDirection();
					barrierList.add(barrier2);
					Barrier barrier3 = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), i*(getWidth()/10), 7*(getHeight()/40));
					barrier3.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
					barrier3.getSpeed().toggleXDirection();
					barrierList.add(barrier3);
				} 
				
				
				
				dd = rand.nextInt(4);
				
				if(dd==0){
					Barrier barrier = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), i*(getWidth()/10), 39*(getHeight()/40));
					barrier.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
					barrier.getSpeed().toggleXDirection();
					barrierList.add(barrier);
				} else if(dd==1){
					Barrier barrier = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), i*(getWidth()/10), 39*(getHeight()/40));
					barrier.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
					barrier.getSpeed().toggleXDirection();
					barrierList.add(barrier);
					Barrier barrier1 = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), i*(getWidth()/10), 37*(getHeight()/40));
					barrier1.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
					barrier1.getSpeed().toggleXDirection();
					barrierList.add(barrier1);
				} else if(dd==2){
					Barrier barrier = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), i*(getWidth()/10), 39*(getHeight()/40));
					barrier.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
					barrier.getSpeed().toggleXDirection();
					barrierList.add(barrier);
					Barrier barrier1 = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), i*(getWidth()/10), 37*(getHeight()/40));
					barrier1.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
					barrier1.getSpeed().toggleXDirection();
					barrierList.add(barrier1);
					Barrier barrier2 = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), i*(getWidth()/10), 7*(getHeight()/8));
					barrier2.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
					barrier2.getSpeed().toggleXDirection();
					barrierList.add(barrier2);
				} else if(dd==3){
					Barrier barrier = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), i*(getWidth()/10), 39*(getHeight()/40));
					barrier.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
					barrier.getSpeed().toggleXDirection();
					barrierList.add(barrier);
					Barrier barrier1 = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), i*(getWidth()/10), 37*(getHeight()/40));
					barrier1.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
					barrier1.getSpeed().toggleXDirection();
					barrierList.add(barrier1);
					Barrier barrier2 = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), i*(getWidth()/10), 7*(getHeight()/8));
					barrier2.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
					barrier2.getSpeed().toggleXDirection();
					barrierList.add(barrier2);
					Barrier barrier3 = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), i*(getWidth()/10), 33*(getHeight()/40));
					barrier3.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
					barrier3.getSpeed().toggleXDirection();
					barrierList.add(barrier3);
				} 
			}
		}
		
		//generate smilies after 40 update cycles. increase generation if game speed increases
		if(cycle%16==0){
			
			//generate random smiley
			/*Random random = new Random();
			int gen;
			gen = random.nextInt(100);*/
			
			/*speedVector = aa/160;
			
			if(speedVector>=4){
				speedVector = 4;
			}*/
			
			/*Barrier barrier = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), z, 50);
			barrier.getSpeed().toggleXDirection();
			barrier.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
			barrierList.add(barrier);*/
			
			x = ran.nextInt(4);
			
			if(x==0){
				Barrier barrier = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), 11*(z/10), aa/40);
				barrier.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
				barrier.getSpeed().toggleXDirection();
				barrierList.add(barrier);
			} else if(x==1){
				Barrier barrier = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), 11*(z/10), aa/40);
				barrier.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
				barrier.getSpeed().toggleXDirection();
				barrierList.add(barrier);
				Barrier barrier1 = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), 11*(z/10), 3*(aa/40));
				barrier1.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
				barrier1.getSpeed().toggleXDirection();
				barrierList.add(barrier1);
			} else if(x==2){
				Barrier barrier = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), 11*(z/10), aa/40);
				barrier.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
				barrier.getSpeed().toggleXDirection();
				barrierList.add(barrier);
				Barrier barrier1 = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), 11*(z/10), 3*(aa/40));
				barrier1.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
				barrier1.getSpeed().toggleXDirection();
				barrierList.add(barrier1);
				Barrier barrier2 = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), 11*(z/10), aa/8);
				barrier2.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
				barrier2.getSpeed().toggleXDirection();
				barrierList.add(barrier2);
			} else if(x==3){
				Barrier barrier = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), 11*(z/10), aa/40);
				barrier.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
				barrier.getSpeed().toggleXDirection();
				barrierList.add(barrier);
				Barrier barrier1 = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), 11*(z/10), 3*(aa/40));
				barrier1.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
				barrier1.getSpeed().toggleXDirection();
				barrierList.add(barrier1);
				Barrier barrier2 = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), 11*(z/10), aa/8);
				barrier2.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
				barrier2.getSpeed().toggleXDirection();
				barrierList.add(barrier2);
				Barrier barrier3 = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), 11*(z/10), 7*(aa/40));
				barrier3.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
				barrier3.getSpeed().toggleXDirection();
				barrierList.add(barrier3);
			} 
			
			
			
			xx = ranx.nextInt(4);
			
			if(xx==0){
				Barrier barrier = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), 11*(z/10), 39*(aa/40));
				barrier.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
				barrier.getSpeed().toggleXDirection();
				barrierList.add(barrier);
			} else if(xx==1){
				Barrier barrier = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), 11*(z/10), 39*(aa/40));
				barrier.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
				barrier.getSpeed().toggleXDirection();
				barrierList.add(barrier);
				Barrier barrier1 = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), 11*(z/10), 37*(aa/40));
				barrier1.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
				barrier1.getSpeed().toggleXDirection();
				barrierList.add(barrier1);
			} else if(xx==2){
				Barrier barrier = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), 11*(z/10), 39*(aa/40));
				barrier.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
				barrier.getSpeed().toggleXDirection();
				barrierList.add(barrier);
				Barrier barrier1 = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), 11*(z/10), 37*(aa/40));
				barrier1.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
				barrier1.getSpeed().toggleXDirection();
				barrierList.add(barrier1);
				Barrier barrier2 = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), 11*(z/10), 7*(aa/8));
				barrier2.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
				barrier2.getSpeed().toggleXDirection();
				barrierList.add(barrier2);
			} else if(xx==3){
				Barrier barrier = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), 11*(z/10), 39*(aa/40));
				barrier.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
				barrier.getSpeed().toggleXDirection();
				barrierList.add(barrier);
				Barrier barrier1 = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), 11*(z/10), 37*(aa/40));
				barrier1.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
				barrier1.getSpeed().toggleXDirection();
				barrierList.add(barrier1);
				Barrier barrier2 = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), 11*(z/10), 7*(aa/8));
				barrier2.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
				barrier2.getSpeed().toggleXDirection();
				barrierList.add(barrier2);
				Barrier barrier3 = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), 11*(z/10), 33*(aa/40));
				barrier3.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
				barrier3.getSpeed().toggleXDirection();
				barrierList.add(barrier3);
			} 
		
			
		}
		
		if(cycle%16==0){
			try {
				for (int i = 0; i < explBarrierList.size(); i++) {
					explBarrierList.remove(i);
					explBarrierList.get(i).getBitmap().recycle();
					explBarrierList.get(i).setBitmap(null);
				}
			} catch (NullPointerException e) {
			} catch (IndexOutOfBoundsException e) {
			}
		}
		
		if(cycle >= explosioncycle+27){
			try {
				for (int i = 0; i < explosionList.size(); i++) {
					explosionList.remove(i);
					explosionList.get(i).getBitmap().recycle();
					explosionList.get(i).setBitmap(null);
				}
				for (int i = 0; i < explosionList1.size(); i++) {
					explosionList1.remove(i);
					explosionList1.get(i).getBitmap().recycle();
					explosionList1.get(i).setBitmap(null);
				}
				for (int i = 0; i < explosionList2.size(); i++) {
					explosionList2.remove(i);
					explosionList2.get(i).getBitmap().recycle();
					explosionList2.get(i).setBitmap(null);
				}
				for (int i = 0; i < explosionList3.size(); i++) {
					explosionList3.remove(i);
					explosionList3.get(i).getBitmap().recycle();
					explosionList3.get(i).setBitmap(null);
				}
				for (int i = 0; i < explosionList4.size(); i++) {
					explosionList4.remove(i);
					explosionList4.get(i).getBitmap().recycle();
					explosionList4.get(i).setBitmap(null);
				}
				for (int i = 0; i < explosionList5.size(); i++) {
					explosionList5.remove(i);
					explosionList5.get(i).getBitmap().recycle();
					explosionList5.get(i).setBitmap(null);
				}
				for (int i = 0; i < explosionList6.size(); i++) {
					explosionList6.remove(i);
					explosionList6.get(i).getBitmap().recycle();
					explosionList6.get(i).setBitmap(null);
				}
				for (int i = 0; i < explosionList7.size(); i++) {
					explosionList7.remove(i);
					explosionList7.get(i).getBitmap().recycle();
					explosionList7.get(i).setBitmap(null);
				}
				for (int i = 0; i < explosionList8.size(); i++) {
					explosionList8.remove(i);
					explosionList8.get(i).getBitmap().recycle();
					explosionList8.get(i).setBitmap(null);
				}
			} catch (NullPointerException e) {
			} catch (IndexOutOfBoundsException e) {
			}
		}
		
		if(cycle >= explcycle+21){
			try {
				for (int i = 0; i < explList.size(); i++) {
					explList.remove(i);
					explList.get(i).getBitmap().recycle();
					explList.get(i).setBitmap(null);
				}
				for (int i = 0; i < explList1.size(); i++) {
					explList1.remove(i);
					explList1.get(i).getBitmap().recycle();
					explList1.get(i).setBitmap(null);
				}
				for (int i = 0; i < explList2.size(); i++) {
					explList2.remove(i);
					explList2.get(i).getBitmap().recycle();
					explList2.get(i).setBitmap(null);
				}
				for (int i = 0; i < explList3.size(); i++) {
					explList3.remove(i);
					explList3.get(i).getBitmap().recycle();
					explList3.get(i).setBitmap(null);
				}
				for (int i = 0; i < explList4.size(); i++) {
					explList4.remove(i);
					explList4.get(i).getBitmap().recycle();
					explList4.get(i).setBitmap(null);
				}
				for (int i = 0; i < explList5.size(); i++) {
					explList5.remove(i);
					explList5.get(i).getBitmap().recycle();
					explList5.get(i).setBitmap(null);
				}
				for (int i = 0; i < explList6.size(); i++) {
					explList6.remove(i);
					explList6.get(i).getBitmap().recycle();
					explList6.get(i).setBitmap(null);
				}
			} catch (NullPointerException e) {
			} catch (IndexOutOfBoundsException e) {
			}
		}
		
		if(cycle%120==0){
			
			x2 = ran2.nextInt(5);
			
			if(x2==0){
				Barrier barrier = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), 11*(z/10), 17*(aa/40));
				barrier.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
				barrier.getSpeed().toggleXDirection();
				barrierList.add(barrier);
				Barrier barrier1 = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), 11*(z/10), 19*(aa/40));
				barrier1.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
				barrier1.getSpeed().toggleXDirection();
				barrierList.add(barrier1);
				Barrier barrier2 = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), 11*(z/10), 21*(aa/40));
				barrier2.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
				barrier2.getSpeed().toggleXDirection();
				barrierList.add(barrier2);
			} else if(x2==1){
				Barrier barrier = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), 11*(z/10), 3*(aa/8));
				barrier.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
				barrier.getSpeed().toggleXDirection();
				barrierList.add(barrier);
				Barrier barrier1 = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), 11*(z/10), 17*(aa/40));
				barrier1.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
				barrier1.getSpeed().toggleXDirection();
				barrierList.add(barrier1);
				Barrier barrier2 = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), 11*(z/10), 19*(aa/40));
				barrier2.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
				barrier2.getSpeed().toggleXDirection();
				barrierList.add(barrier2);
				Barrier barrier3 = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), 11*(z/10), 21*(aa/40));
				barrier3.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
				barrier3.getSpeed().toggleXDirection();
				barrierList.add(barrier3);
				Barrier barrier4 = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), 11*(z/10), 23*(aa/40));
				barrier4.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
				barrier4.getSpeed().toggleXDirection();
				barrierList.add(barrier4);
			} else if(x2==2){
				Barrier barrier = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), 11*(z/10), 13*(aa/40));
				barrier.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
				barrier.getSpeed().toggleXDirection();
				barrierList.add(barrier);
				Barrier barrier1 = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), 11*(z/10), 3*(aa/8));
				barrier1.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
				barrier1.getSpeed().toggleXDirection();
				barrierList.add(barrier1);
				Barrier barrier2 = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), 11*(z/10), 17*(aa/40));
				barrier2.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
				barrier2.getSpeed().toggleXDirection();
				barrierList.add(barrier2);
				Barrier barrier3 = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), 11*(z/10), 19*(aa/40));
				barrier3.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
				barrier3.getSpeed().toggleXDirection();
				barrierList.add(barrier3);
				Barrier barrier4 = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), 11*(z/10), 21*(aa/40));
				barrier4.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
				barrier4.getSpeed().toggleXDirection();
				barrierList.add(barrier4);
				Barrier barrier5 = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), 11*(z/10), 23*(aa/40));
				barrier5.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
				barrier5.getSpeed().toggleXDirection();
				barrierList.add(barrier5);
				Barrier barrier6 = new Barrier(BitmapFactory.decodeResource(getResources(), R.drawable.barrier), 11*(z/10), 5*(aa/8));
				barrier6.getSpeed().setXv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
				barrier6.getSpeed().toggleXDirection();
				barrierList.add(barrier6);
			} else if(x2==3 || x2==4){
				
			}
			
		}
		
		int loc;
		
		if(cycle>500 && cycle<1500 && cycle%60==0){
			
			xh = ranh.nextInt(2);
			xhh = ranh.nextInt(3);
			loc = (xhh+1)*(aa/4);
			
			if(xh==0){
				Helicopter helicopter = new Helicopter(BitmapFactory.decodeResource(getResources(), R.drawable.heli0), 11*(z/10), loc);
				Helicopter helicopter1 = new Helicopter(BitmapFactory.decodeResource(getResources(), R.drawable.heli1), 11*(z/10), loc);
				Helicopter helicopter2 = new Helicopter(BitmapFactory.decodeResource(getResources(), R.drawable.heli2), 11*(z/10), loc);
				Helicopter helicopter3 = new Helicopter(BitmapFactory.decodeResource(getResources(), R.drawable.heli3), 11*(z/10), loc);
				helicopter.getSpeed().setXv((float) (2*speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
				helicopter1.getSpeed().setXv((float) (2*speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
				helicopter2.getSpeed().setXv((float) (2*speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
				helicopter3.getSpeed().setXv((float) (2*speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
				helicopter.getSpeed().toggleXDirection();
				helicopter1.getSpeed().toggleXDirection();
				helicopter2.getSpeed().toggleXDirection();
				helicopter3.getSpeed().toggleXDirection();
				helicopterList.add(helicopter);
				helicopterList1.add(helicopter1);
				helicopterList2.add(helicopter2);
				helicopterList3.add(helicopter3);
			} else if(xh==1){
				
			}
			
		} else if(cycle>1500 && cycle%30==0){
			
			xh = ranh.nextInt(2);
			xhh = ranh.nextInt(3);
			loc = (xhh+1)*(aa/4);
			
			if(xh==0){
				Helicopter helicopter = new Helicopter(BitmapFactory.decodeResource(getResources(), R.drawable.heli0), 11*(z/10), loc);
				Helicopter helicopter1 = new Helicopter(BitmapFactory.decodeResource(getResources(), R.drawable.heli1), 11*(z/10), loc);
				Helicopter helicopter2 = new Helicopter(BitmapFactory.decodeResource(getResources(), R.drawable.heli2), 11*(z/10), loc);
				Helicopter helicopter3 = new Helicopter(BitmapFactory.decodeResource(getResources(), R.drawable.heli3), 11*(z/10), loc);
				helicopter.getSpeed().setXv((float) (2*speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
				helicopter1.getSpeed().setXv((float) (2*speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
				helicopter2.getSpeed().setXv((float) (2*speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
				helicopter3.getSpeed().setXv((float) (2*speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
				helicopter.getSpeed().toggleXDirection();
				helicopter1.getSpeed().toggleXDirection();
				helicopter2.getSpeed().toggleXDirection();
				helicopter3.getSpeed().toggleXDirection();
				helicopterList.add(helicopter);
				helicopterList1.add(helicopter1);
				helicopterList2.add(helicopter2);
				helicopterList3.add(helicopter3);
			} else if(xh==1){
				
			}
			
		}
		
		Random ranhel = new Random();
		int hel;
		
		if(cycle>1000 && cycle%30==0){
			
			xh = ranh.nextInt(2);
			try {
				hel = ranhel.nextInt(helicopterList.size());
			} catch (IllegalArgumentException e) {
				hel=0;
				xh=1;
			}
						
			if(xh==0){
				EnemyMissile enemyMissile = new EnemyMissile(BitmapFactory.decodeResource(getResources(), R.drawable.enemymissile), helicopterList.get(hel).getX(), helicopterList.get(hel).getY());
				enemyMissile.getSpeed().setXv((float) (3*speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
				enemyMissile.getSpeed().toggleXDirection();
				enemyMissileList.add(enemyMissile);
			} else if(xh==1){
				
			}
			
		}
			
		try{
			
		for(int i=0;i<barrierList.size();i++){
			if (barrierList.get(i).getSpeed().getxDirection() == Speed.DIRECTION_LEFT
					&& barrierList.get(i).getX() + barrierList.get(i).getBitmap().getWidth() / 2 <= 0) {
				barrierList.get(i).getBitmap().recycle();
				barrierList.get(i).setBitmap(null);
				barrierList.remove(i);
			}
		}
		
		for(int i=0;i<helicopterList.size();i++){
			if (helicopterList.get(i).getSpeed().getxDirection() == Speed.DIRECTION_LEFT
					&& helicopterList.get(i).getX() + helicopterList.get(i).getBitmap().getWidth() / 2 <= 0) {
				helicopterList.get(i).getBitmap().recycle();
				helicopterList1.get(i).getBitmap().recycle();
				helicopterList2.get(i).getBitmap().recycle();
				helicopterList3.get(i).getBitmap().recycle();
				helicopterList.get(i).setBitmap(null);
				helicopterList1.get(i).setBitmap(null);
				helicopterList2.get(i).setBitmap(null);
				helicopterList3.get(i).setBitmap(null);
				helicopterList.remove(i);
				helicopterList1.remove(i);
				helicopterList2.remove(i);
				helicopterList3.remove(i);
			}
		}
		
		for(int i=0;i<missileList.size();i++){
			if (missileList.get(i).getSpeed().getxDirection() == Speed.DIRECTION_RIGHT
					&& missileList.get(i).getX() - missileList.get(i).getBitmap().getWidth() / 2 >= getWidth()) {
				missileList.get(i).getBitmap().recycle();
				missileList.get(i).setBitmap(null);
				missileList.remove(i);
			}
		}
		
		for(int i=0;i<enemyMissileList.size();i++){
			if (enemyMissileList.get(i).getSpeed().getxDirection() == Speed.DIRECTION_LEFT
					&& enemyMissileList.get(i).getX() - enemyMissileList.get(i).getBitmap().getWidth() / 2 >= getWidth()) {
				enemyMissileList.get(i).getBitmap().recycle();
				enemyMissileList.get(i).setBitmap(null);
				enemyMissileList.remove(i);
			}
		}
		
		} catch (IndexOutOfBoundsException e) {
			
		} catch (NullPointerException e) {
			
		}
		
		// Update the smilies
		
		try {
			Iterator<Barrier> iter = barrierList.iterator();
			while(iter.hasNext()) {
				iter.next().update();
			}
			Iterator<Helicopter> iter1 = helicopterList.iterator();
			while(iter1.hasNext()) {
				iter1.next().update();
			}
			Iterator<Helicopter> iter2 = helicopterList1.iterator();
			while(iter2.hasNext()) {
				iter2.next().update();
			}
			Iterator<Helicopter> iter3 = helicopterList2.iterator();
			while(iter3.hasNext()) {
				iter3.next().update();
			}
			Iterator<Helicopter> iter4 = helicopterList3.iterator();
			while(iter4.hasNext()) {
				iter4.next().update();
			}
			Iterator<Missile> iter5 = missileList.iterator();
			while(iter5.hasNext()) {
				iter5.next().update();
			}
			Iterator<EnemyMissile> iter6 = enemyMissileList.iterator();
			while(iter6.hasNext()) {
				iter6.next().update();
			}
			
		} catch (IndexOutOfBoundsException e) {
			
		} catch (ConcurrentModificationException e) {
			
		} catch (NullPointerException e) {
		
		}
		
		if(upped){
			
			dhoniScroll.getHspeed().setYv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
			dhoni.getHspeed().setYv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
			dhoni1.getHspeed().setYv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
			dhoni2.getHspeed().setYv((float) (speedVector * Math.pow(SPEED_INCREASE_FACTOR, speedIncreaser)));
			
			dhoniScroll.update();
			dhoni.update();
			dhoni1.update();
			dhoni2.update();
			
		}
		
		
				
	}
	
	
	/**
	 * Detect collisions during the game play
	 */
	public void collisions(){ 
	try {
		//helicopter-barrier collisions
			for(int i=0;i<barrierList.size();i++)
			{
				/*if (barrierList.get(i).getX() - barrierList.get(i).getBitmap().getWidth() / 2 < dhoni.getX() + dhoni.getBitmap().getWidth() / 2 && barrierList.get(i).getX() + barrierList.get(i).getBitmap().getWidth() / 2 > dhoni.getX() - dhoni.getBitmap().getWidth() / 2){
					if (barrierList.get(i).getY() - barrierList.get(i).getBitmap().getHeight() / 2 < dhoni.getY() + dhoni.getBitmap().getHeight() / 2 && barrierList.get(i).getY() + barrierList.get(i).getBitmap().getHeight() / 2 > dhoni.getY() - dhoni.getBitmap().getHeight() / 2){
						warned=warned+1;
						barrierList.get(i).getBitmap().recycle();
						barrierList.get(i).setBitmap(null);
						barrierList.remove(i);
					}
				}*/
				
				if (barrierList.get(i).getX() - getWidth() / 20 < dhoni.getX() + getWidth() / 16 && barrierList.get(i).getX() + getWidth() / 20 > dhoni.getX() - getWidth() / 16){
					if (barrierList.get(i).getY() - getHeight() / 40 < dhoni.getY() + getHeight() / 24 && barrierList.get(i).getY() + getHeight() / 40 > dhoni.getY() - getHeight() / 24){
						if (soundoff.equals("false")){
							blast.start();
						}
						warned=warned+1;
						if(warned==1){
							finalExplosioncycle = cycle;
							finalExplosion = new FinalExplosion(BitmapFactory.decodeResource(getResources(),R.drawable.explosion),
									dhoni.getX(), dhoni.getY());
							finalExplosionList.add(finalExplosion);
							finalExplosion1 = new FinalExplosion(BitmapFactory.decodeResource(getResources(),R.drawable.explosion1),
									dhoni.getX(), dhoni.getY());
							finalExplosionList1.add(finalExplosion1);
							finalExplosion2 = new FinalExplosion(BitmapFactory.decodeResource(getResources(),R.drawable.explosion2),
									dhoni.getX(), dhoni.getY());
							finalExplosionList2.add(finalExplosion2);
							finalExplosion3 = new FinalExplosion(BitmapFactory.decodeResource(getResources(),R.drawable.explosion3),
									dhoni.getX(), dhoni.getY());
							finalExplosionList3.add(finalExplosion3);
							finalExplosion4 = new FinalExplosion(BitmapFactory.decodeResource(getResources(),R.drawable.explosion4),
									dhoni.getX(), dhoni.getY());
							finalExplosionList4.add(finalExplosion4);
							finalExplosion5 = new FinalExplosion(BitmapFactory.decodeResource(getResources(),R.drawable.explosion5),
									dhoni.getX(), dhoni.getY());
							finalExplosionList5.add(finalExplosion5);
							finalExplosion6 = new FinalExplosion(BitmapFactory.decodeResource(getResources(),R.drawable.explosion6),
									dhoni.getX(), dhoni.getY());
							finalExplosionList6.add(finalExplosion6);
							finalExplosion7 = new FinalExplosion(BitmapFactory.decodeResource(getResources(),R.drawable.explosion7),
									dhoni.getX(), dhoni.getY());
							finalExplosionList7.add(finalExplosion7);
							finalExplosion8 = new FinalExplosion(BitmapFactory.decodeResource(getResources(),R.drawable.explosion8),
									dhoni.getX(), dhoni.getY());
							finalExplosionList8.add(finalExplosion8);
						}
						barrierList.get(i).getBitmap().recycle();
						barrierList.get(i).setBitmap(null);
						barrierList.remove(i);
					}
				}
				
			}
			
		//helicopter-enemy helicopter collisions
			for(int i=0;i<helicopterList.size();i++)
			{
				if (helicopterList.get(i).getX() - getWidth() / 16 < dhoni.getX() + getWidth() / 16 && helicopterList.get(i).getX() + getWidth() / 16 > dhoni.getX() - getWidth() / 16){
					if (helicopterList.get(i).getY() - getHeight() / 24 < dhoni.getY() + getHeight() / 24 && helicopterList.get(i).getY() + getHeight() / 24 > dhoni.getY() - getHeight() / 24){
						if (soundoff.equals("false")){
							blast.start();
						}
						warned=warned+1;
						if(warned==1){
							finalExplosioncycle = cycle;
							finalExplosion = new FinalExplosion(BitmapFactory.decodeResource(getResources(),R.drawable.explosion),
									dhoni.getX(), dhoni.getY());
							finalExplosionList.add(finalExplosion);
							finalExplosion1 = new FinalExplosion(BitmapFactory.decodeResource(getResources(),R.drawable.explosion1),
									dhoni.getX(), dhoni.getY());
							finalExplosionList1.add(finalExplosion1);
							finalExplosion2 = new FinalExplosion(BitmapFactory.decodeResource(getResources(),R.drawable.explosion2),
									dhoni.getX(), dhoni.getY());
							finalExplosionList2.add(finalExplosion2);
							finalExplosion3 = new FinalExplosion(BitmapFactory.decodeResource(getResources(),R.drawable.explosion3),
									dhoni.getX(), dhoni.getY());
							finalExplosionList3.add(finalExplosion3);
							finalExplosion4 = new FinalExplosion(BitmapFactory.decodeResource(getResources(),R.drawable.explosion4),
									dhoni.getX(), dhoni.getY());
							finalExplosionList4.add(finalExplosion4);
							finalExplosion5 = new FinalExplosion(BitmapFactory.decodeResource(getResources(),R.drawable.explosion5),
									dhoni.getX(), dhoni.getY());
							finalExplosionList5.add(finalExplosion5);
							finalExplosion6 = new FinalExplosion(BitmapFactory.decodeResource(getResources(),R.drawable.explosion6),
									dhoni.getX(), dhoni.getY());
							finalExplosionList6.add(finalExplosion6);
							finalExplosion7 = new FinalExplosion(BitmapFactory.decodeResource(getResources(),R.drawable.explosion7),
									dhoni.getX(), dhoni.getY());
							finalExplosionList7.add(finalExplosion7);
							finalExplosion8 = new FinalExplosion(BitmapFactory.decodeResource(getResources(),R.drawable.explosion8),
									dhoni.getX(), dhoni.getY());
							finalExplosionList8.add(finalExplosion8);
						}
						helicopterList.get(i).getBitmap().recycle();
						helicopterList1.get(i).getBitmap().recycle();
						helicopterList2.get(i).getBitmap().recycle();
						helicopterList3.get(i).getBitmap().recycle();
						helicopterList.get(i).setBitmap(null);
						helicopterList1.get(i).setBitmap(null);
						helicopterList2.get(i).setBitmap(null);
						helicopterList3.get(i).setBitmap(null);
						helicopterList.remove(i);
						helicopterList1.remove(i);
						helicopterList2.remove(i);
						helicopterList3.remove(i);
					}
				}
				
			}
			
		//helicopter-enemy missile collisions
			for(int i=0;i<enemyMissileList.size();i++)
			{
				if (enemyMissileList.get(i).getX() - getWidth() / 30 < dhoni.getX() + getWidth() / 16 && enemyMissileList.get(i).getX() + getWidth() / 16 > dhoni.getX() - getWidth() / 30){
					if (enemyMissileList.get(i).getY() - getHeight() / 60 < dhoni.getY() + getHeight() / 24 && enemyMissileList.get(i).getY() + getHeight() / 24 > dhoni.getY() - getHeight() / 60){
						warned=warned+1;
						if(warned==1){
							finalExplosioncycle = cycle;
							finalExplosion = new FinalExplosion(BitmapFactory.decodeResource(getResources(),R.drawable.explosion),
									dhoni.getX(), dhoni.getY());
							finalExplosionList.add(finalExplosion);
							finalExplosion1 = new FinalExplosion(BitmapFactory.decodeResource(getResources(),R.drawable.explosion1),
									dhoni.getX(), dhoni.getY());
							finalExplosionList1.add(finalExplosion1);
							finalExplosion2 = new FinalExplosion(BitmapFactory.decodeResource(getResources(),R.drawable.explosion2),
									dhoni.getX(), dhoni.getY());
							finalExplosionList2.add(finalExplosion2);
							finalExplosion3 = new FinalExplosion(BitmapFactory.decodeResource(getResources(),R.drawable.explosion3),
									dhoni.getX(), dhoni.getY());
							finalExplosionList3.add(finalExplosion3);
							finalExplosion4 = new FinalExplosion(BitmapFactory.decodeResource(getResources(),R.drawable.explosion4),
									dhoni.getX(), dhoni.getY());
							finalExplosionList4.add(finalExplosion4);
							finalExplosion5 = new FinalExplosion(BitmapFactory.decodeResource(getResources(),R.drawable.explosion5),
									dhoni.getX(), dhoni.getY());
							finalExplosionList5.add(finalExplosion5);
							finalExplosion6 = new FinalExplosion(BitmapFactory.decodeResource(getResources(),R.drawable.explosion6),
									dhoni.getX(), dhoni.getY());
							finalExplosionList6.add(finalExplosion6);
							finalExplosion7 = new FinalExplosion(BitmapFactory.decodeResource(getResources(),R.drawable.explosion7),
									dhoni.getX(), dhoni.getY());
							finalExplosionList7.add(finalExplosion7);
							finalExplosion8 = new FinalExplosion(BitmapFactory.decodeResource(getResources(),R.drawable.explosion8),
									dhoni.getX(), dhoni.getY());
							finalExplosionList8.add(finalExplosion8);
						}
						enemyMissileList.get(i).getBitmap().recycle();
						enemyMissileList.get(i).setBitmap(null);
						enemyMissileList.remove(i);
					}
				}
				
			}
			
		//missile-enemy helicopter collisions
			for(int i=0;i<helicopterList.size();i++)
			{
				for(int j=0;j<missileList.size();j++)
				{
					if (helicopterList.get(i).getX() - getWidth() / 16 < missileList.get(j).getX() + getWidth() / 30 && helicopterList.get(i).getX() + getWidth() / 16 > missileList.get(j).getX() - getWidth() / 30){
						if (helicopterList.get(i).getY() - getHeight() / 24 < missileList.get(j).getY() + getHeight() / 60 && helicopterList.get(i).getY() + getHeight() / 24 > missileList.get(j).getY() - getHeight() / 60){
							if (soundoff.equals("false")){
								blast.start();
							}
							score=score+100;
							explosioncycle = cycle;
							explosion = new Explosion(BitmapFactory.decodeResource(getResources(),R.drawable.explosion),
									helicopterList.get(i).getX(), helicopterList.get(i).getY());
							explosionList.add(explosion);
							explosion1 = new Explosion(BitmapFactory.decodeResource(getResources(),R.drawable.explosion1),
									helicopterList.get(i).getX(), helicopterList.get(i).getY());
							explosionList1.add(explosion1);
							explosion2 = new Explosion(BitmapFactory.decodeResource(getResources(),R.drawable.explosion2),
									helicopterList.get(i).getX(), helicopterList.get(i).getY());
							explosionList2.add(explosion2);
							explosion3 = new Explosion(BitmapFactory.decodeResource(getResources(),R.drawable.explosion3),
									helicopterList.get(i).getX(), helicopterList.get(i).getY());
							explosionList3.add(explosion3);
							explosion4 = new Explosion(BitmapFactory.decodeResource(getResources(),R.drawable.explosion4),
									helicopterList.get(i).getX(), helicopterList.get(i).getY());
							explosionList4.add(explosion4);
							explosion5 = new Explosion(BitmapFactory.decodeResource(getResources(),R.drawable.explosion5),
									helicopterList.get(i).getX(), helicopterList.get(i).getY());
							explosionList5.add(explosion5);
							explosion6 = new Explosion(BitmapFactory.decodeResource(getResources(),R.drawable.explosion6),
									helicopterList.get(i).getX(), helicopterList.get(i).getY());
							explosionList6.add(explosion6);
							explosion7 = new Explosion(BitmapFactory.decodeResource(getResources(),R.drawable.explosion7),
									helicopterList.get(i).getX(), helicopterList.get(i).getY());
							explosionList7.add(explosion7);
							explosion8 = new Explosion(BitmapFactory.decodeResource(getResources(),R.drawable.explosion8),
									helicopterList.get(i).getX(), helicopterList.get(i).getY());
							explosionList8.add(explosion8);
							helicopterList.get(i).getBitmap().recycle();
							helicopterList1.get(i).getBitmap().recycle();
							helicopterList2.get(i).getBitmap().recycle();
							helicopterList3.get(i).getBitmap().recycle();
							helicopterList.get(i).setBitmap(null);
							helicopterList1.get(i).setBitmap(null);
							helicopterList2.get(i).setBitmap(null);
							helicopterList3.get(i).setBitmap(null);
							helicopterList.remove(i);
							helicopterList1.remove(i);
							helicopterList2.remove(i);
							helicopterList3.remove(i);
							missileList.get(j).getBitmap().recycle();
							missileList.get(j).setBitmap(null);
							missileList.remove(j);
						}
					}
				}
			}
			
		//missile-enemy missile collisions
			for(int i=0;i<enemyMissileList.size();i++)
			{
				for(int j=0;j<missileList.size();j++)
				{
					if (enemyMissileList.get(i).getX() - getWidth() / 30 < missileList.get(j).getX() + getWidth() / 30 && enemyMissileList.get(i).getX() + getWidth() / 30 > missileList.get(j).getX() - getWidth() / 30){
						if (enemyMissileList.get(i).getY() - getHeight() / 60 < missileList.get(j).getY() + getHeight() / 60 && enemyMissileList.get(i).getY() + getHeight() / 60 > missileList.get(j).getY() - getHeight() / 60){
							if (soundoff.equals("false")){
								missileBlast.start();
							}
							score=score+50;
							explcycle = cycle;
							expl = new Expl(BitmapFactory.decodeResource(getResources(),R.drawable.expl),
									enemyMissileList.get(i).getX(), enemyMissileList.get(i).getY());
							explList.add(expl);
							expl1 = new Expl(BitmapFactory.decodeResource(getResources(),R.drawable.expl1),
									enemyMissileList.get(i).getX(), enemyMissileList.get(i).getY());
							explList1.add(expl1);
							expl2 = new Expl(BitmapFactory.decodeResource(getResources(),R.drawable.expl2),
									enemyMissileList.get(i).getX(), enemyMissileList.get(i).getY());
							explList2.add(expl2);
							expl3 = new Expl(BitmapFactory.decodeResource(getResources(),R.drawable.expl3),
									enemyMissileList.get(i).getX(), enemyMissileList.get(i).getY());
							explList3.add(expl3);
							expl4 = new Expl(BitmapFactory.decodeResource(getResources(),R.drawable.expl4),
									enemyMissileList.get(i).getX(), enemyMissileList.get(i).getY());
							explList4.add(expl4);
							expl5 = new Expl(BitmapFactory.decodeResource(getResources(),R.drawable.expl5),
									enemyMissileList.get(i).getX(), enemyMissileList.get(i).getY());
							explList5.add(expl5);
							expl6 = new Expl(BitmapFactory.decodeResource(getResources(),R.drawable.expl6),
									enemyMissileList.get(i).getX(), enemyMissileList.get(i).getY());
							explList6.add(expl6);
							enemyMissileList.get(i).getBitmap().recycle();
							enemyMissileList.get(i).setBitmap(null);
							enemyMissileList.remove(i);
							missileList.get(j).getBitmap().recycle();
							missileList.get(j).setBitmap(null);
							missileList.remove(j);
						}
					}
				}
			}
			
		//missile-barrier collisions
			for(int i=0;i<barrierList.size();i++)
			{
				for(int j=0;j<missileList.size();j++)
				{
					if (barrierList.get(i).getX() - getWidth() / 20 < missileList.get(j).getX() + getWidth() / 30 && barrierList.get(i).getX() + getWidth() / 20 > missileList.get(j).getX() - getWidth() / 30){
						if (barrierList.get(i).getY() - getHeight() / 40 < missileList.get(j).getY() + getHeight() / 60 && barrierList.get(i).getY() + getHeight() / 40 > missileList.get(j).getY() - getHeight() / 60){
							if (soundoff.equals("false")){
								barrierBlast.start();
							}
							score=score+10;
							explBarrier = new ExplBarrier(BitmapFactory.decodeResource(getResources(),R.drawable.explbarrier),
									barrierList.get(i).getX(), barrierList.get(i).getY());
							explBarrierList.add(explBarrier);
							barrierList.get(i).getBitmap().recycle();
							barrierList.get(i).setBitmap(null);
							barrierList.remove(i);
							missileList.get(j).getBitmap().recycle();
							missileList.get(j).setBitmap(null);
							missileList.remove(j);
							
							
						}
					}
				}
			}
	} catch (IndexOutOfBoundsException e) {
		
	}
		
		if (dhoni.getY() - getHeight() / 24 > getHeight()){
			warned=warned+1;
		}
		
		if((warned>=1) && (cycle>=finalExplosioncycle+27)){
			thread.setRunning(false);
			
			try {
				for(int i=0;i<barrierList.size();i++){
					barrierList.get(i).getBitmap().recycle();
					barrierList.get(i).setBitmap(null);
					barrierList.remove(i);
				}
				
				for(int i=0;i<helicopterList.size();i++){
					helicopterList.get(i).getBitmap().recycle();
					helicopterList.get(i).setBitmap(null);
					helicopterList.remove(i);
				}
				
				for(int i=0;i<helicopterList1.size();i++){
					helicopterList1.get(i).getBitmap().recycle();
					helicopterList1.get(i).setBitmap(null);
					helicopterList1.remove(i);
				}
				
				for(int i=0;i<helicopterList2.size();i++){
					helicopterList2.get(i).getBitmap().recycle();
					helicopterList2.get(i).setBitmap(null);
					helicopterList2.remove(i);
				}
				
				for(int i=0;i<helicopterList3.size();i++){
					helicopterList3.get(i).getBitmap().recycle();
					helicopterList3.get(i).setBitmap(null);
					helicopterList3.remove(i);
				}
				
				for(int i=0;i<missileList.size();i++){
					missileList.get(i).getBitmap().recycle();
					missileList.get(i).setBitmap(null);
					missileList.remove(i);
				}
				
				for(int i=0;i<enemyMissileList.size();i++){
					enemyMissileList.get(i).getBitmap().recycle();
					enemyMissileList.get(i).setBitmap(null);
					enemyMissileList.remove(i);
				}
				
				for(int i=0;i<explBarrierList.size();i++){
					explBarrierList.get(i).getBitmap().recycle();
					explBarrierList.get(i).setBitmap(null);
					explBarrierList.remove(i);
				}
				
				for(int i=0;i<explosionList.size();i++){
					explosionList.get(i).getBitmap().recycle();
					explosionList.get(i).setBitmap(null);
					explosionList.remove(i);
				}
				
				for(int i=0;i<explosionList1.size();i++){
					explosionList1.get(i).getBitmap().recycle();
					explosionList1.get(i).setBitmap(null);
					explosionList1.remove(i);
				}
				
				for(int i=0;i<explosionList2.size();i++){
					explosionList2.get(i).getBitmap().recycle();
					explosionList2.get(i).setBitmap(null);
					explosionList2.remove(i);
				}
				
				for(int i=0;i<explosionList3.size();i++){
					explosionList3.get(i).getBitmap().recycle();
					explosionList3.get(i).setBitmap(null);
					explosionList3.remove(i);
				}
				
				for(int i=0;i<explosionList4.size();i++){
					explosionList4.get(i).getBitmap().recycle();
					explosionList4.get(i).setBitmap(null);
					explosionList4.remove(i);
				}
				
				for(int i=0;i<explosionList5.size();i++){
					explosionList5.get(i).getBitmap().recycle();
					explosionList5.get(i).setBitmap(null);
					explosionList5.remove(i);
				}
				
				for(int i=0;i<explosionList6.size();i++){
					explosionList6.get(i).getBitmap().recycle();
					explosionList6.get(i).setBitmap(null);
					explosionList6.remove(i);
				}
				
				for(int i=0;i<explosionList7.size();i++){
					explosionList7.get(i).getBitmap().recycle();
					explosionList7.get(i).setBitmap(null);
					explosionList7.remove(i);
				}
				
				for(int i=0;i<explosionList8.size();i++){
					explosionList8.get(i).getBitmap().recycle();
					explosionList8.get(i).setBitmap(null);
					explosionList8.remove(i);
				}
				
				for(int i=0;i<explList.size();i++){
					explList.get(i).getBitmap().recycle();
					explList.get(i).setBitmap(null);
					explList.remove(i);
				}
				
				for(int i=0;i<explList1.size();i++){
					explList1.get(i).getBitmap().recycle();
					explList1.get(i).setBitmap(null);
					explList1.remove(i);
				}
				
				for(int i=0;i<explList2.size();i++){
					explList2.get(i).getBitmap().recycle();
					explList2.get(i).setBitmap(null);
					explList2.remove(i);
				}
				
				for(int i=0;i<explList3.size();i++){
					explList3.get(i).getBitmap().recycle();
					explList3.get(i).setBitmap(null);
					explList3.remove(i);
				}
				
				for(int i=0;i<explList4.size();i++){
					explList4.get(i).getBitmap().recycle();
					explList4.get(i).setBitmap(null);
					explList4.remove(i);
				}
				
				for(int i=0;i<explList5.size();i++){
					explList5.get(i).getBitmap().recycle();
					explList5.get(i).setBitmap(null);
					explList5.remove(i);
				}
				
				for(int i=0;i<explList6.size();i++){
					explList6.get(i).getBitmap().recycle();
					explList6.get(i).setBitmap(null);
					explList6.remove(i);
				}
				
				for(int i=0;i<finalExplosionList.size();i++){
					finalExplosionList.get(i).getBitmap().recycle();
					finalExplosionList.get(i).setBitmap(null);
					finalExplosionList.remove(i);
				}
				
				for(int i=0;i<finalExplosionList1.size();i++){
					finalExplosionList1.get(i).getBitmap().recycle();
					finalExplosionList1.get(i).setBitmap(null);
					finalExplosionList1.remove(i);
				}
				
				for(int i=0;i<finalExplosionList2.size();i++){
					finalExplosionList2.get(i).getBitmap().recycle();
					finalExplosionList2.get(i).setBitmap(null);
					finalExplosionList2.remove(i);
				}
				
				for(int i=0;i<finalExplosionList3.size();i++){
					finalExplosionList3.get(i).getBitmap().recycle();
					finalExplosionList3.get(i).setBitmap(null);
					finalExplosionList3.remove(i);
				}
				
				for(int i=0;i<finalExplosionList4.size();i++){
					finalExplosionList4.get(i).getBitmap().recycle();
					finalExplosionList4.get(i).setBitmap(null);
					finalExplosionList4.remove(i);
				}
				
				for(int i=0;i<finalExplosionList5.size();i++){
					finalExplosionList5.get(i).getBitmap().recycle();
					finalExplosionList5.get(i).setBitmap(null);
					finalExplosionList5.remove(i);
				}
				
				for(int i=0;i<finalExplosionList6.size();i++){
					finalExplosionList6.get(i).getBitmap().recycle();
					finalExplosionList6.get(i).setBitmap(null);
					finalExplosionList6.remove(i);
				}
				
				for(int i=0;i<finalExplosionList7.size();i++){
					finalExplosionList7.get(i).getBitmap().recycle();
					finalExplosionList7.get(i).setBitmap(null);
					finalExplosionList7.remove(i);
				}
				
				for(int i=0;i<finalExplosionList8.size();i++){
					finalExplosionList8.get(i).getBitmap().recycle();
					finalExplosionList8.get(i).setBitmap(null);
					finalExplosionList8.remove(i);
				}
				
				barrierList.clear();
				helicopterList.clear();
				helicopterList1.clear();
				helicopterList2.clear();
				helicopterList3.clear();
				missileList.clear();
				enemyMissileList.clear();
				explBarrierList.clear();
				explosionList.clear();
				explosionList1.clear();
				explosionList2.clear();
				explosionList3.clear();
				explosionList4.clear();
				explosionList5.clear();
				explosionList6.clear();
				explosionList7.clear();
				explosionList8.clear();
				explList.clear();
				explList1.clear();
				explList2.clear();
				explList3.clear();
				explList4.clear();
				explList5.clear();
				explList6.clear();
				finalExplosionList.clear();
				finalExplosionList1.clear();
				finalExplosionList2.clear();
				finalExplosionList3.clear();
				finalExplosionList4.clear();
				finalExplosionList5.clear();
				finalExplosionList6.clear();
				finalExplosionList7.clear();
				finalExplosionList8.clear();
			} catch (NullPointerException e) {
			}
			
			//thread.setRunning(false);
			//paused = true;
			
			System.gc();
			
			Intent intent = new Intent((Activity)getContext(), GameOverActivity.class);
			intent.putExtra(HIGH_SCORE, scoreString);
			intent.putExtra(SOUND_OFF_STRING, soundoff);
			((Activity)getContext()).startActivity(intent);
			((Activity)getContext()).finish();
		}
				
	}

}

